import * as path from 'path'
import { think } from 'thinkjs'
const isDev = think.env === 'development'
const id_16 = require('id-16')
const id = id_16.generator(4)


module.exports = [
  {
    handle: 'meta',
    options: {
      logRequest: isDev,
      sendResponseTime: isDev
    }
  },
  {
    handle: 'resource',
    enable: true,
    options: {
      root: path.join(think.ROOT_PATH, 'www'),
      publicPath: /^\/(static|favicon\.ico)/
    }
  },
  {
    handle: 'trace',
    enable: !think.isCli,
    options: {
      debug: true,
      sourceMap: false,
      error(err:any, ctx:any) {
        let _id=think.datetime(new Date(),'YYYYMMDDHHmmss'+id())
        think.logger.error("异常编号:" + _id + " , 异常内容:" + err)
        return ctx.fail(err.errno,"请求失败！错误ID："+_id)
      }
    }
  },
  {
    handle: 'payload',
    options: {
      keepExtensions: true,
      limit: '5mb'
    }
  },
  {
    handle: 'router',
    options: {}
  },
  {
    handle: 'paramMid',
    options: {}
  },

  'logic',
  'controller'
];
